//本程序用于计算从1开始的连续整数中选定一个数，再随机抽取两个数，选定的数最大的概率
package OwnThought;

import java.util.Scanner;

public class MaxPob {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请选择最大的数");
        int endNum = sc.nextInt();
        int less_num, allResult, i = 0;
        int[] arr = new int[endNum];
        for (int j = 0; j < endNum; j++) {
            arr[j] = j + 1;
        }
        System.out.println("请选择一个数");
        int choosedNum = sc.nextInt();
        while (choosedNum > endNum || choosedNum < 1) {
            System.out.print("你输入的数字超出了范围，请重新输入:>");
            choosedNum = sc.nextInt();
        }
        allResult = (endNum - 1) * (endNum - 2);
        for (int detec : arr) {
            if (detec == choosedNum)
                break;
            i++;
        }
        less_num = i;
        float final_result = (float) (i * (i - 1)) / allResult;
        System.out.println(final_result);
    }
}
